F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

DZY Loves Sorting

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1370    Accepted Submission(s): 465


Problem Description
DZY has a sequence $a[1..n]$. It is a permutation of integers $1 \sim n$.

Now he wants to perform two types of operations:

$0 \,\,l \,\,r$: Sort $a[l..r]$ in increasing order.

$1\,\, l \,\,r$: Sort $a[l..r]$ in decreasing order.

After doing all the operations, he will tell you a position $k$, and ask you the value of $a[k]$.
 

Input
First line contains $t$, denoting the number of testcases.

$t$ testcases follow. For each testcase:

First line contains $n,m$. $m$ is the number of operations.

Second line contains $n$ space-separated integers $a[1],a[2],\cdots,a[n]$, the initial sequence. We ensure that it is a permutation of $1\sim n$.

Then $m$ lines follow. In each line there are three integers $opt,l,r$ to indicate an operation.

Last line contains $k$.

($1\le t \le 50,1\le n,m \le 100000,1\le k \le n, 1\le l\le r\le n, opt \in \{0,1\}$. Sum of $n$ in all testcases does not exceed $150000$. Sum of $m$ in all testcases does not exceed $150000$)
 

Output
For each testcase, output one line - the value of $a[k]$ after performing all $m$ operations.
 

Sample Input
1 6 3 1 6 2 5 3 4 0 1 4 1 3 6 0 2 4 3
 

Sample Output
5
 

Hint

1 6 2 5 3 4 -> [1 2 5 6] 3 4 -> 1 2 [6 5 4 3] -> 1 [2 5 6] 4 3. At last $a[3]=5$.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-28 13:35:18, Gzip enabled